<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * News short summary.
 *
 * News description.
 *
 * @version 1.0
 * @author GALAXY
 */
class News extends Pre_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->Model('New_model');
        $this->load->Model('Menu_model');
    }

    public function newslist()
    {
        $menuid=$this->uri->segment(3);
        $menu_model=$this->Menu_model->get_menu_by_id($menuid);
        //获取seo
        $config_model=$this->get_config();
        $config_model->title= !empty($menu_model->title)?$config_model->title.'_'.$menu_model->title:$config_model->title;
        $data['config_model']=$config_model;

        //获取左侧栏目,顶部栏目元素，面包屑
        $left_nav=null;
        $top_nav_title=null;
        $crumbs=null;
        $icon=null;
        $array_high=$this->get_high_item_left_nav_crumbs($menuid,$left_nav,$top_nav_title,$crumbs,$icon);
        $data['icon']=$icon;
        $data['crumbs']=$crumbs;
        $data['left_nav']=$left_nav;
        $data['top_nav_title']=$top_nav_title;
        //获取高亮栏目
        $data['top_high']=$array_high[0];
        if(count($array_high)>=2)
        {
            $data['left_high']=$array_high[1];
        }
        //获取新闻列表
        $cupge=$this->input->get('page');
        $cupge=empty($cupge) || $cupge=="0"?1:$cupge;
        $data['cupge']=$cupge;
        $pagesize=10;
        $data['pagesize']=$pagesize;
        $new_page_objs=$this->New_model->get_page($cupge,$pagesize,"a.*","new","order by weight desc, adddate desc, new_id desc ","new_id","where menuid=$menuid","");
        $this->load->library('page');
        $p=new Page();
        $data['menuid']=$menuid;
        $data['newslist']=arrayToObject($new_page_objs['objlist']);
        $p->init($new_page_objs['count'][0]->_count,5,$cupge,$pagesize,site_url('news/newslist/'.$menuid));
        $data['links']=$p->showPages(1);

        $this->load->view('Pre/news/newlist.html',$data);
    }

    public function newsinfo()
    {
        $new_id=$this->uri->segment(3);
        $new_model=$this->New_model->get_new_by_id($new_id);

        $config_model=$this->get_config();
        $config_model->title= !empty($new_model->title)?$config_model->title.'_'.$new_model->title:$config_model->title;
        $config_model->keyword= !empty($new_model->keyword)?$new_model->keyword:$config_model->keyword;
        $config_model->description= !empty($new_model->description)?$new_model->description:$config_model->description;
        $data['config_model']=$config_model;

        //获取左侧栏目,顶部栏目元素，面包屑
        $left_nav=null;
        $top_nav_title=null;
        $crumbs=null;
        $icon=null;
        $array_high=$this->get_high_item_left_nav_crumbs($new_model->menuid,$left_nav,$top_nav_title,$crumbs,$icon);
        $data['icon']=$icon;
        $data['crumbs']=$crumbs;
        $data['left_nav']=$left_nav;
        $data['top_nav_title']=$top_nav_title;
        //获取高亮栏目
        $data['top_high']=$array_high[0];
        if(count($array_high)>=2)
        {
            $data['left_high']=$array_high[1];
        }
        $data['new_model']=$new_model;
        $this->load->view('Pre/news/newsinfo.html',$data);
    }
}